// pages/index/index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    userInfo: {},
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function (options) {
    let that=this;
    this.setData({
      hasUserInfo:app.globalData.hasUserInfo
    }) ;
    console.log(app.globalData.hasUserInfo)
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      console.log(2)
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
        console.log(res.userInfo)
      }
    } else {
      console.log(3)
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    };
    var common = require('../../utils/common');
    common.HttpRequst(true, 'commend/service_list', 2, '', '', 'get', false, function setting (dataCon) {
      that.setData({
        classify: dataCon.data
      });
      console.log(that.data.classify)
    });
    common.HttpRequst(true, 'commend/all_category_list', 2, '', '', 'get', false, function setting(dataCon) {
      that.setData({
        hotList: dataCon.data
      });
    });
    common.HttpRequst(true, 'commend/banner', 2, '', '', 'get', false, function setting(dataCon) {
      that.setData({
        imgUrls: dataCon.data
      });
    });
    wx.request({
      url:'http://www.duanpei.site/index.php?tp=commend/banner',
      data:'',
      success:function(res){
        console.log(res)
      }
    })
    
  },

  onReady: function () {

  },

  onShow: function () {

  },
  onHide: function () {

  },

  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  categrayList:function(e){
    wx.navigateTo({
      url: 'voiceActor/voiceActor?stype_id='+e.currentTarget.dataset.id
    })
  },
  toDetail:function(e){
    wx.navigateTo({
      url: 'detail/detail?id=' + e.currentTarget.dataset.id,
    })
  }
  
})